import { User } from "@Tea/model"
import { SystemContext } from "../context/SystemContext"

export class UserState {
  static inst: UserState = new UserState()
  private cache: Set<number> = new Set()

  static getInstance() {
    return UserState.inst
  }

  /**
   * @use 创建缓存
   */
  async initCache() {
    const userList = (await SystemContext.getInstance().getDeactivateUser())[0]
    
    userList.forEach(u=> this.cache.add(u.userId))
  }

  /**
   * @use 停用
   */
  deactivate(userId: number) {
    this.cache.add(userId)
  }

  /**
   * @use 判断状态是否禁用
   */
  judgeState(userId: number) {
    return this.cache.has(userId)
  }

  /**
   * @use 启用
   */
  enable(userId: number) {
    this.cache.delete(userId)
  }
}